<?php

/* 
 * 在线报名
 */

namespace Admin\Controller;

class BaomingController extends ComController
{
    //报名列表
    public function index(){
        $uid = $_SESSION['uid'];
        $member = M('member')->field('level')->where(array('uid'=>$uid))->find();
        if($member['level'] == 1){
            $where['uid'] = $uid;
        }
        $is_pay = $_GET['is_pay'];
        if($is_pay){
            $where['sc_baoming.is_pay'] = $is_pay;
        }
        $p= intval($_GET['p'])?$_GET['p']:1;
        $pagesize = 15;#每页数量
        $offset = $pagesize * ($p - 1);//计算记录偏移量
        $data = M('baoming')
                ->field(" sc_baoming.*,m.uid,u.name as u_name,m.name as m_name,b.body_name as b_name,c.name as c_name ")
                ->join(" sc_user as u on u.id=sc_baoming.user_id ","LEFT")
                ->join(" sc_member as m on m.uid=sc_baoming.sc_id ","LEFT")
                ->join(" sc_body as b on b.id=sc_baoming.body_id ","LEFT")
                ->join(" sc_class as c on c.id=sc_baoming.class_id ","LEFT")
                ->where($where)
                ->limit($offset . ',' . $pagesize)
                ->order('sc_baoming.add_time desc')
                ->select();
        $count = M('baoming')
                ->where($where)
                ->count();
        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();
        $this->assign('page',$page);
        $this->assign('data',$data);
        $this->display();
    }
    //删除
    public function del(){
        $id = I('get.id');
        $res = M('baoming')->where(array('id'=>$id))->delete();
        if($res){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }
}